﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;

/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {

    public AutoComplete () {
        
    }

    [WebMethod]
    public string[] AutoCompleteAjaxRequest(string prefixText, int count) {
        List<string> ajaxDataCollection = new List<string>();
        DataTable dt = new DataTable();
        dt = GetDataWithPrefix(prefixText);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ajaxDataCollection.Add(dt.Rows[i]["Name"].ToString());
            }
        }
        return ajaxDataCollection.ToArray();
    }
    public DataTable GetDataWithPrefix(string prefixText)
    {
        string sql = "select * from trieuchung where Name like '%" + prefixText + "%'";
        class_database cd = new class_database();
        DataTable dt = new DataTable();
        dt = cd.GetDataTable(sql);
        return dt;
    }
    
}
